
import {fetchUtils} from './FetchUtils';

/**
 * 这是全局 API
 */

export function loginIn(data) {
  const url ="/sys/login/sysLogin";
  return fetchUtils({
    url:url,
    method:"post",
    data:data
  });
}


/*全局监控-配送车辆监控统计摘要查询*/
export function queryMonitorIndicator(id) {


  let url = "/dist/webCarMonitor/queryMonitorIndicator";
  url += id !== -1 ? `?deptId=${id}` : "";
  return fetchUtils({
    url:url,
    method: 'get',
  })
}
// 全局监控-配送车辆监控车辆状态列表查询
export function queryMonitorCarStatusList(id) {
  let url = "/dist/webCarMonitor/queryMonitorCarStatusList";
  url += id !== -1 ? `?deptId=${id}` : "";
  return fetchUtils({
    url,
    method: 'get'
  })
}

// 全局监控-配送车辆监控报警列表查询
export function queryMonitorAlarmList(params,id) {
  // let url = `/dist/webCarMonitor/queryMonitorAlarmList?alarmState=${alarmState}&beginDate=${beginDate}&endDate=${endDate}`;
  let realUrl = dealUrlParams("/dist/webCarMonitor/queryMonitorAlarmList",params);
  realUrl += id !== -1 ? `&deptId=${id}` : "";

  console.log("tes " + realUrl);
  return fetchUtils({
    realUrl,
    method: 'get'
  })
}

// 车辆管理-配送车辆列表查询
/*
 * pageNumber  页码
 * pageSize  页大小
 * tagSerial  设备终端序列号
 * plateNumber 车牌号
 * deptId  部门ID
 * isActive  是否启用 0-禁用；1-启用
 */
export function queryDistCarList(params) {
  let realUrl = dealUrlParams("/dist/webCarManager/queryDistCarList",params);
  return fetchUtils({
    url: realUrl,
    method: 'get',
  })
}
//全局监控-配送车辆监控车辆回放记录查询
export function queryCarReplayRealRecord(params) {
  return fetchUtils({
    url: `/dist/webCarMonitor/queryCarReplayRealRecord`,
    method: 'get',
    params
  })
}
//车辆管理-配送车辆查询
export function queryDistCar(id) {
  return fetchUtils({
    url: `/dist/webCarManager/queryDistCar?id=${id}`,
    method: 'get'
  })
}
//车辆管理-配送车辆启用/禁用
export function updateDistCarIsActive(data) {
  return fetchUtils({
    url: `/dist/webCarManager/updateDistCarIsActive`,
    method: 'put',
    data
  })
}

// 报警管理-配送车辆监控报警列表查询
/*
 * pageNumber  页码
 * pageSize  页大小
 * beginDate  开始时间
 * endDate 结束时间
 * alarmState  报警状态：0：报警，1：报警解除
 */
export function queryCarAlarmList(params) {
  return fetchUtils({
    url: `/dist/webCarAlarm/queryCarAlarmList`,
    method: 'get',
    params
  })
}
//车辆管理-配送车辆终端号是否可用查询
export function queryCarTagSerialIsUsed(params) {
  return fetchUtils({
    url: `/dist/webCarManager/queryCarTagSerialIsUsed`,
    method: 'get',
    params
  })
}
//报警管理-配送车辆监控报警查询
export function queryCarAlarm(id) {
  return fetchUtils({
    url: `/dist/webCarAlarm/queryCarAlarm?id=${id}`,
    method: 'get'
  })
}
// {
//   "carName": "string,车辆名称",
//   "deptId": "int,部门ID",
//   "dictCarStatus": "1",
//   "dictCarType": "1",
//   "driverUserUuid": "string,用户UUID",  queryAllDeptAndUserTree
//   "isMotor": "int,是否机动车,1 是；0 否",
//   "isOutsource": "int,是否外包,1 是；0 否",
//   "plateNumber": "string,车牌号",
//   "purchaseDate": "date,购置日期",
//   "description": "string,车辆描述",
//   "tagSerial": "A0000202",
//   "usedDate": "date,使用日期"
// }
//车辆管理-配送车辆添加
export function addDistCar(data) {
  data.dictCarStatus = "1";
  data.dictCarType = "1";
  return fetchUtils({
    url: `/dist/webCarManager/addDistCar`,
    method: 'post',
    data:data
  })
}

//车辆管理-配送车辆修改
export function updateDistCar(data) {
  data.dictCarStatus = "1";
  data.dictCarType = "1";
  return fetchUtils({
    url: `/dist/webCarManager/updateDistCar`,
    method: 'put',
    data:data
  })
}
//车辆管理-配送车辆修改
export function queryCarChargingList(params) {
  return fetchUtils({
    url: `/dist/webCarCharging/queryCarChargingList`,
    method: 'get',
    params
  })
}
//充电管理-配送车辆充电记录图表查询
//carId=394&beginDate=2019-04-22+14:05:41&endDate=2019-04-22+15:05:41
export function queryCarChargingChart(params) {
  return fetchUtils({
    url: `/dist/webCarCharging/queryCarChargingChart?carId=${params.carId}&beginDate=${params.beginDate}&endDate=${params.endDate}`,
    method: 'get'
  })
}

/**
 * 车辆管理-司机信息查询
 */
export function queryDistDriver(userUuid) {
  const urlParams = dealUrlParams("/dist/webCarManager/queryDistDriver",{
    id:userUuid
  });
  return fetchUtils({
    url: urlParams,
    method: 'get'
  })
}
/**
 * 车辆管理-司机信息修改
 */
export function updateDistDriver(data) {
  return fetchUtils({
    url: `/dist/webCarManager/updateDistDriver`,
    method: 'post',
    data
  })
}

/**
 * 全局监控-未登记车辆监控统计摘要查询
 */
export function queryUnregMonitorIndicator(params) {
  return fetchUtils({
    url: `/dist/webCarMonitor/queryUnregMonitorIndicator`,
    method: 'get',
    params
  })
}
/**
 * 全局监控-未登记车辆监控车辆状态列表查询
 */
export function queryUnregMonitorCarStatusList(params) {
  return fetchUtils({
    url: `/dist/webCarMonitor/queryUnregMonitorCarStatusList`,
    method: 'get',
    params
  })
}
/**
 * 全局监控-未登记车辆监控车辆状态列表查询
 */
export function queryDeptLngLat(id) {
  return fetchUtils({
    url: `/org/manager/queryDeptLngLat?id=${id}`,
    method: 'get'
  })
}

/**
 * 全局监控-车辆监控报警统计摘要查询
 */
export function queryMonitorAlarmIndicator(params) {
  return fetchUtils({
    url: `/dist/webCarMonitor/queryMonitorAlarmIndicator`,
    method: 'get',
    params
  })
}


function dealUrlParams(url,params) {
  if (params) {
    let paramsArray = [];
    //拼接参数
    Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key]));
    if (url.search(/\?/) === -1) {
      url += '?' + paramsArray.join('&')
    } else {
      url += '&' + paramsArray.join('&')
    }
  }
  return url;
}
